package com.ruoyi.parking.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.parking.domain.ParkWhitelist;
import com.ruoyi.parking.dto.WhitelistAndCar;
import com.ruoyi.parking.service.IParkCarService;
import com.ruoyi.parking.service.IParkWhitelistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 白名单Controller
 * 
 * @author chenkai
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/parking/whitelist")
public class ParkWhitelistController extends BaseController
{
    @Autowired
    private IParkWhitelistService parkWhitelistService;
    @Autowired
    private IParkCarService parkCarService;
    /**
     * 查询白名单列表
     */
    @PreAuthorize("@ss.hasPermi('parking:whitelist:list')")
    @GetMapping("/list")
    public TableDataInfo list(WhitelistAndCar whitelistAndCar)
    {
        startPage();
        List<WhitelistAndCar> list = parkWhitelistService.selectParkWhitelistList(whitelistAndCar);
        return getDataTable(list);
    }

    /**
     * 导出白名单列表
     */
//    @PreAuthorize("@ss.hasPermi('parking:whitelist:export')")
//    @Log(title = "白名单", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, WhitelistAndCar whitelistAndCar)
//    {
//        List<WhitelistAndCar> list = parkWhitelistService.selectParkWhitelistList(whitelistAndCar);
//        ExcelUtil<ParkWhitelist> util = new ExcelUtil<ParkWhitelist>(ParkWhitelist.class);
//        util.exportExcel(response, list, "白名单数据");
//    }

    /**
     * 获取白名单详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:whitelist:query')")
    @GetMapping(value = "/{whitelistId}")
    public AjaxResult getInfo(@PathVariable("whitelistId") Integer whitelistId)
    {
        return success(parkWhitelistService.selectParkWhitelistByWhitelistId(whitelistId));
    }

    /**
     * 新增白名单
     */
    @PreAuthorize("@ss.hasPermi('parking:whitelist:add')")
    @Log(title = "白名单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkWhitelist parkWhitelist)
    {

        return toAjax(parkWhitelistService.insertParkWhitelist(parkWhitelist));

    }

    /**
     * 修改白名单
     */
    @PreAuthorize("@ss.hasPermi('parking:whitelist:edit')")
    @Log(title = "白名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkWhitelist parkWhitelist)
    {
        return toAjax(parkWhitelistService.updateParkWhitelist(parkWhitelist));
    }

    /**
     * 删除白名单
     */
    @PreAuthorize("@ss.hasPermi('parking:whitelist:remove')")
    @Log(title = "白名单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{whitelistIds}")
    public AjaxResult remove(@PathVariable Integer[] whitelistIds)
    {
        return toAjax(parkWhitelistService.deleteParkWhitelistByWhitelistIds(whitelistIds));
    }
}
